package github.kawaiior.yuanchuxiuzhen.common.entity.addon.model;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import github.kawaiior.yuanchuxiuzhen.common.entity.addon.StoneCamelEntity;
import github.kawaiior.yuanchuxiuzhen.util.RenderUtil;
import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.util.math.MathHelper;

public class StoneCamelEntityModel extends EntityModel<StoneCamelEntity> {
    private final ModelRenderer leftarm;
    
    private final ModelRenderer rightarm;
    
    private final ModelRenderer body;
    
    private final ModelRenderer leftleg;
    
    private final ModelRenderer rightleg;
    
    private final ModelRenderer head;

    public StoneCamelEntityModel(){
        this.textureWidth=128;
        this.textureHeight=64;
        this.leftarm=new ModelRenderer(this);
        this.leftarm.setRotationPoint(5.0F,6.0F,-10.0F);
        addBox(this.leftarm, 116, 14, 0.0F, 4.0F, -2.0F, 3, 14, 3, 0.0F, false);
        addBox(this.leftarm, 110, 0, 1.0F, -4.0F, -3.0F, 3, 8, 6, 0.0F, false);
        this.rightarm=new ModelRenderer(this);
        this.rightarm.setRotationPoint(-5.0F,6.0F,-10.0F);
        addBox(this.rightarm, 116, 14, -3.0F, 4.0F, -2.0F, 3, 14, 3, 0.0F, false);
        addBox(this.rightarm, 110, 0, -4.0F, -4.0F, -3.0F, 3, 8, 6, 0.0F, false);
        this.body=new ModelRenderer(this);
        this.body.setRotationPoint(0.0F,24.0F,0.0F);
        addBox(this.body, 22, 17, -6.0F, -26.0F, -14.0F, 12, 12, 10, 0.0F, false);
        addBox(this.body, 22, 39, -7.0F, -26.0F, -4.0F, 14, 13, 12, 0.0F, false);
        addBox(this.body, 74, 46, -6.0F, -24.0F, 8.0F, 12, 10, 8, 0.0F, false);
        addBox(this.body, 62, 29, -5.0F, -30.0F, -13.0F, 10, 4, 10, 0.0F, false);
        addBox(this.body, 56, 15, -4.0F, -34.0F, -12.0F, 8, 4, 8, 0.0F, false);
        addBox(this.body, 62, 29, -5.0F, -29.0F, 0.0F, 10, 5, 10, 0.0F, false);
        addBox(this.body, 56, 15, -4.0F, -33.0F, 1.0F, 8, 4, 8, 0.0F, false);
        addBox(this.body, 116, 46, 0.0F, -24.0F, 16.0F, 0, 12, 6, 0.0F, false);
        this.leftleg=new ModelRenderer(this);
        this.leftleg.setRotationPoint(5.0F,5.0F,12.0F);
        addBox(this.leftleg, 116, 14, 0.0F, 5.0F, -1.0F, 3, 14, 3, 0.0F, false);
        addBox(this.leftleg, 90, 0, 1.0F, -4.0F, -4.0F, 3, 9, 7, 0.0F, false);
        this.rightleg=new ModelRenderer(this);
        this.rightleg.setRotationPoint(-5.0F,5.0F,12.0F);
        addBox(this.rightleg, 116, 14, -3.0F, 5.0F, -2.0F, 3, 14, 3, 0.0F, false);
        addBox(this.rightleg, 90, 0, -4.0F, -4.0F, -4.0F, 3, 9, 7, 0.0F, false);
        this.head=new ModelRenderer(this);
        this.head.setRotationPoint(0.0F,3.0F,-14.0F);
        addBox(this.head, 0, 0, -3.5F, -11.0F, -15.0F, 7, 6, 7, 0.0F, false);
        addBox(this.head, 0, 13, -2.5F, -9.0F, -19.0F, 5, 4, 4, 0.0F, false);
        addBox(this.head, 0, 21, -3.0F, -5.0F, -11.0F, 6, 8, 1, 0.0F, false);
        addBox(this.head, 0, 43, -4.0F, -2.0F, -7.0F, 8, 8, 3, 0.0F, false);
        addBox(this.head, 0, 30, -4.0F, -5.0F, -10.0F, 8, 10, 3, 0.0F, false);
        addBox(this.head, 0, 54, -4.0F, -4.0F, -2.0F, 8, 8, 2, 0.0F, false);
        addBox(this.head, 0, 54, -4.0F, -3.0F, -4.0F, 8, 8, 2, 0.0F, false);
    }

    private void addBox(ModelRenderer mb, int tx, int ty, float x, float y, float z, float width, float height, float depth, float delta, boolean mirrorIn){
        ModelRenderer mr = new ModelRenderer(this);
        mb.addChild(mr);
        mr.setTextureOffset(tx, ty).addBox(x,y,z,width,height,depth,delta,mirrorIn);
    }

    @Override
    public void setRotationAngles(StoneCamelEntity entityIn, float limbSwing,
                                  float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
        this.head.rotateAngleY = netHeadYaw / 57.295776F;
        this.head.rotateAngleX = headPitch / 57.295776F;
        this.rightleg.rotateAngleX = MathHelper.cos(limbSwing * 1.0F) * 1.0F * limbSwingAmount;
        this.rightarm.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F + 3.1415927F) * limbSwingAmount;
        this.leftleg.rotateAngleX = MathHelper.cos(limbSwing * 1.0F) * -1.0F * limbSwingAmount;
        this.leftarm.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F) * limbSwingAmount;
    }

    @Override
    public void render(MatrixStack matrixStackIn, IVertexBuilder bufferIn, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) {
        this.leftarm.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.rightarm.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.body.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.leftleg.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.rightleg.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.head.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
    }
}